package com.smxy.mall.controller;

import com.smxy.mall.annotation.CurrentUser;
import com.smxy.mall.common.Response;
import com.smxy.mall.model.Current;
import com.smxy.mall.model.request.car.CarDelReq;
import com.smxy.mall.model.request.car.CarRemoveReq;
import com.smxy.mall.model.request.car.CarReq;
import com.smxy.mall.service.CarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@Api(tags = "购物车")
@RestController
@RequestMapping("/car")
public class CarController {
    @Resource
    private CarService carService;

    @ApiOperation("加入购物车")
    @PostMapping("/add")
    public Object add(@Valid CarReq carReq, @CurrentUser Current current) {
        return Response.success(carService.save(carReq,current));
    }

    @ApiOperation("减少购物车")
    @PostMapping("/remove")
    public Object remove(@Valid CarRemoveReq carRemoveReq,@CurrentUser Current current) {
        return Response.success(carService.remove(carRemoveReq,current));
    }

    @ApiOperation("清空购物车")
    @PostMapping("/del")
    public Object del(@Valid CarDelReq carDelReq,@CurrentUser Current current){
        return Response.success(carService.delete(carDelReq,current));
    }

    @ApiOperation("购物车列表带商品信息")
    @GetMapping("/goodsList")
    public Object goodsList(@CurrentUser Current current,@RequestParam("shopId")Integer shopId) {
        return Response.success(carService.carList(current.getUserId(),shopId));
    }

    @ApiOperation("购物车列表，不带商品信息")
    @GetMapping("/list")
    public Object list(@CurrentUser Current current) {
        return Response.success(carService.findByUserId(current));
    }

    @ApiOperation("购物车各个商品数量")
    @GetMapping("/getGoodsNum")
    public Object getGoodsNum(@CurrentUser Current current){
        return Response.success(carService.getGoodsNum(current));
    }
}
